package com.tarena.lbs.common.marketing.converter;

import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.marketing.bo.CouponCodeBO;
import com.tarena.lbs.pojo.marketing.dos.CouponCodeDO;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import com.tarena.lbs.pojo.marketing.vo.CouponCodeVO;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CouponCodeConverter {

    public PageResult<CouponCodeVO> assemblePageVOS(BasePageList<CouponCodeBO> bos, UserCouponQuery query) {
        if (bos == null || bos.getTotal() == 0) {
            return null;
        }
        PageResult<CouponCodeVO> result = new PageResult<>();
        List<CouponCodeVO> vos = new ArrayList<>();
        for (CouponCodeBO temp : bos.getList()) {
            CouponCodeVO vo = new CouponCodeVO();
            BeanUtils.copyProperties(temp,vo);
            vos.add(vo);
        }
        result.setTotal(bos.getTotal());
        result.setObjects(vos);
        result.setPageNo(query.getPageNo());
        result.setPageSize(query.getPageSize());
        return result;
    }

    public CouponCodeVO bo2vo(CouponCodeBO bo) {
        if (bo == null) {
            return null;
        }
        CouponCodeVO vo = new CouponCodeVO();
        BeanUtils.copyProperties(bo,vo);
        return vo;
    }

    public CouponCodeBO do2bo(CouponCodeDO tempDo) {
        if (tempDo == null) {
            return null;
        }
        CouponCodeBO bo = new CouponCodeBO();
        BeanUtils.copyProperties(tempDo,bo);
        return bo;
    }
}
